package com.qd.qx.bean;

/**
 * Created by YS
 */


import com.qd.common.commonutils.SPUtils;
import com.qd.qx.app.AppConstants;

import java.io.Serializable;

/**
 * 用户对象保存用户基本数据
 */
public class UserData implements Serializable {

    private static UserData mInstance;

    private String loginName = "";//登陆名 loginCode
    private String chatName = "";//聊天id 名字+域名
    private String password = "";//登陆密码
    private String headerImg = "";//用户头像

    private String realName = "";//汉字名字
    private String appToken = "";//	用户登录凭证
    private String mobile = "";//	联系电话
    private String appKey = "";//	用户登录凭证
    private String refCode = "";//	员工编号
    private String email = "";//	Email
    private String openfirePwd = "";//xmpp 登陆密码

    private String officeCode = "";//部门编码
    private String officeName = "";//部门名称


    private UserData() {

    }

    //单例模式，节省资源
    public static UserData getInstance() {
        if (mInstance == null) {
            synchronized (UserData.class) {
                if (mInstance == null) {
                    UserData user = SPUtils.getSharedBeanData(AppConstants.USER_DATA, UserData.class);
                    if (user == null) {
                        mInstance = new UserData();
                    } else {
                        mInstance = user;
                    }
                    return mInstance;
                }
            }
        }
        return mInstance;
    }


    /**
     * 设置数据并保存
     *
     * @param loginName
     * @param chatName
     * @param password
     * @param headerImg
     */
    public void initUserData(String loginName, String chatName, String password, String headerImg, String realName,
                             String appToken, String mobile, String appKey, String refCode, String email, String openfirePwd,
                             String officeCode, String officeName) {
        this.loginName = loginName;
        this.chatName = chatName;
        this.password = password;
        this.headerImg = headerImg;
        this.realName = realName;
        this.appToken = appToken;
        this.mobile = mobile;
        this.appKey = appKey;
        this.refCode = refCode;
        this.email = email;
        this.openfirePwd = openfirePwd;
        this.officeCode = officeCode;
        this.officeName = officeName;
        SPUtils.setSharedBeanData(AppConstants.USER_DATA, mInstance);
    }

    /**
     * 移除用户
     */
    public void removeUserData() {
        SPUtils.setSharedBeanData(AppConstants.USER_DATA, null);
        mInstance = null;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getChatName() {
        return chatName;
    }

    public void setChatName(String chatName) {
        this.chatName = chatName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getHeaderImg() {
        return headerImg;
    }

    public void setHeaderImg(String headerImg) {
        this.headerImg = headerImg;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getAppToken() {
        return appToken;
    }

    public void setAppToken(String appToken) {
        this.appToken = appToken;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAppKey() {
        return appKey;
    }

    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }

    public String getRefCode() {
        return refCode;
    }

    public void setRefCode(String refCode) {
        this.refCode = refCode;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getOpenfirePwd() {
        return openfirePwd;
    }

    public void setOpenfirePwd(String openfirePwd) {
        this.openfirePwd = openfirePwd;
    }

    public String getOfficeCode() {
        return officeCode;
    }

    public void setOfficeCode(String officeCode) {
        this.officeCode = officeCode;
    }

    public String getOfficeName() {
        return officeName;
    }

    public void setOfficeName(String officeName) {
        this.officeName = officeName;
    }
}
